package com.yc.spring.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.*;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/7/31
 * Email haijunzhou@hnit.edu.cn
 */

@Configuration   // bean.xml
@ComponentScan({"com.yc.spring.demo.biz",
        "com.yc.spring.demo.mapper",
        "com.yc.spring.demo.web"})
public class AnnoConfig {

    @Bean("person")  // <bean id="person">
    @DependsOn("aaaa")
    public Person person(){
        return new Person();
    }

    @Bean("aaaa")  // <bean id="aaaa">
    @Primary
    public Person aaaa(){
        return new Person(18,"李四");
    }

    @Bean  // <bean id="person1">
    public Person person1(){
        return Person.staticCreate();
    }

    @Bean(initMethod = "init", destroyMethod = "destroy")
    // <bean id="person2">  接口注入
    public Person person2(
            @Autowired @Qualifier("person1")Person person1){
        return person1.create();
    }

    @Bean
    @Scope("prototype")
    @Lazy
    // <bean id="person3">  接口注入
    public Person person3(
            @Autowired @Qualifier("person1") Person person1){
        Person person = new Person();
        person.mather = new Person();
        person.mather.setName("武松她妈");
        person.father = person1;
        return person;
    }
}
